//
//  YMSocketManager.h
//  YMIM
//
//  Created by reyzhang on 2022/3/18.
//

#import <Foundation/Foundation.h>


NS_ASSUME_NONNULL_BEGIN

typedef NSString * YMNotificationEvent NS_STRING_ENUM;

FOUNDATION_EXPORT YMNotificationEvent const YMNotificationEventForSocketDidOpen;
FOUNDATION_EXPORT YMNotificationEvent const YMNotificationEventForSocketDidFailWithError;
FOUNDATION_EXPORT YMNotificationEvent const YMNotificationEventForSocketDidCloseWithReason;
FOUNDATION_EXPORT YMNotificationEvent const YMNotificationEventForSocketDidReceiveData;



@class YMSocketManager;
@class YMMessage;
@protocol YMSocketDelegate <NSObject>

@optional
/**
 接收到消息后的回调
 */
- (void)ymSocket:(YMSocketManager *)webSocket didReceiveMessage:(YMMessage *)message;

/**
 socket打开
 */
- (void)ymSocketDidOpen:(YMSocketManager *)webSocket;

/**
 socket连接失败
 */
- (void)ymSocket:(YMSocketManager *)webSocket didFailWithError:(NSError *)error;

/**
 连接关闭
 */
- (void)ymSocket:(YMSocketManager *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason;
@end


@interface YMSocketManager : NSObject

@property (nonatomic, weak) id<YMSocketDelegate> delegate;


/**
 * 单例， 唯一初始化入口，全局访问点
 */
+ (instancetype)sharedManager;



/**
 根据用户token建立连接
 */
- (void)connectWithToken:(NSString *)token;

/**
 断开连接
 */
- (void)disConnect;


/**
 发送消息
 */
- (void)sendMessage:(NSString *)msg;

/**
 发送Ping
 */
- (void)ping;


@end

NS_ASSUME_NONNULL_END
